package uit.ce03.game_ninja;

import uit.ce03.game_ninja.MainGame.Luudiem;
import uit.ce03.game_ninja.MainGame.MainGame_BaseGame;
import uit.ce03.game_ninja.Static.Static_Const;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Application;
import android.content.DialogInterface;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.text.AlteredCharSequence;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class NinjaActivity extends Activity {
	Button button_play,button_about,button_highscore,button_help,button_quit;
	MediaPlayer mp;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ninja);
        button_play = (Button)findViewById(R.id.playgame);
        button_highscore = (Button)findViewById(R.id.option);
        button_about = (Button)findViewById(R.id.about);
        button_help = (Button) findViewById(R.id.help);
        button_quit = (Button)findViewById(R.id.quit);
        
        mp = MediaPlayer.create(this, R.raw.nhac_nen_game_1);
        if(Static_Const.AmThanh)
        {
        	mp.start();
        	mp.setLooping(true);
        }
       
        
        button_play.getBackground().setAlpha(5);
        button_about.getBackground().setAlpha(5);
        button_help.getBackground().setAlpha(5);
        button_highscore.getBackground().setAlpha(5);
        button_quit.getBackground().setAlpha(5);
        button_play.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new Intent(getApplication(),MainGame_BaseGame.class);
				startActivity(i);
				mp.stop();
				finish();
			}
		});
        button_about.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new Intent(getApplicationContext(),Game_about.class);
				startActivity(i);
				
			}
		});
        button_help.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new Intent(getApplication(),Game_help.class);
				startActivity(i);
				
			}
		});
        button_highscore.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new Intent(getApplicationContext(),Game_HighScore.class);
				startActivity(i);
				
			}
		});
        button_quit.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				AlertDialog.Builder alertDialog = new AlertDialog.Builder(NinjaActivity.this);
				alertDialog.setTitle("Exit");
				alertDialog.setMessage("Bạn Có Muốn Thoát Ra khỏi Game Không ?");
				alertDialog.setIcon(R.drawable.icon_exit);
				alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
					
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						mp.stop();
						finish();
					}
				});
				alertDialog.setNegativeButton("NO",new DialogInterface.OnClickListener() {
					
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						dialog.cancel();
					}
				});
				alertDialog.show();

			}
		});
    }
    @Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(keyCode == KeyEvent.KEYCODE_BACK){
			AlertDialog.Builder alertDialog = new AlertDialog.Builder(NinjaActivity.this);
			alertDialog.setTitle("Exit");
			alertDialog.setMessage("Bạn Có Muốn Thoát Ra khỏi Game Không ?");
			alertDialog.setIcon(R.drawable.icon_exit);
			alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
				
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
					mp.stop();
					finish();
				}
			});
			alertDialog.setNegativeButton("NO",new DialogInterface.OnClickListener() {
				
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
					dialog.cancel();
				}
			});
			alertDialog.show();
		}
		return super.onKeyDown(keyCode, event);
	}


    
    
}
